package com.main;

import java.util.HashMap;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;

public class Character {
	public int xpos;
	public int ypos;
	public enum Type {Stay,AxeE,AxeW,AxeN, Up, Down, Left, Right};
	public enum Direction {North,East,South,West};
	public Type type;
	public Direction direction;
	public HashMap<Type, Sprite[]> sprites;
	public Sprite activeSprite;
	public int animlength;
	public Inventory inventory;
	public HashMap<Integer, StaticInventoryData.GameObject> hotKeys;
	public Community community;
	public Character(int x,int y) {
		community = new Community();
		inventory = new Inventory();
		type = Type.Down;
		xpos = x;
		ypos = y;
		sprites = new HashMap<Type,Sprite[]>();
		hotKeys = new HashMap<Integer, StaticInventoryData.GameObject>();
		hotKeys.put(1,StaticInventoryData.GameObject.Hand);
		hotKeys.put(2,StaticInventoryData.GameObject.Shovel);
		hotKeys.put(3,StaticInventoryData.GameObject.Nothing);
		hotKeys.put(4,StaticInventoryData.GameObject.Nothing);
		hotKeys.put(5,StaticInventoryData.GameObject.Nothing);
		sprites.put(Type.Stay, StaticTextures.characterMS);
		sprites.put(Type.AxeE, StaticTextures.characterAAE);
		sprites.put(Type.AxeW, StaticTextures.characterAAW);
		sprites.put(Type.AxeN, StaticTextures.characterAAN);
		sprites.put(Type.Up, StaticTextures.characterMU);
		sprites.put(Type.Down, StaticTextures.characterMD);
		sprites.put(Type.Left, StaticTextures.characterML);
		sprites.put(Type.Right, StaticTextures.characterMR);
		activeSprite = StaticTextures.characterDown;
	}
	public void setPos(int x, int y) {
		xpos = x;
		ypos = y;
	}
	public void render(SpriteBatch sb){
		if(type == Type.AxeW){
			activeSprite.setPosition((xpos*Game.tileWidth)-32,ypos*Game.tileHeight);
		}
		else{
			activeSprite.setPosition(xpos*Game.tileWidth,ypos*Game.tileHeight);
		}
		activeSprite.draw(sb);
	}

	public void still(Direction dir){
		type = Type.Stay;
		if(dir == Direction.West){
			activeSprite = StaticTextures.characterLeft;
		}
		else if(dir == Direction.East)
			activeSprite = StaticTextures.characterRight;

		else if(dir == Direction.North)
			activeSprite = StaticTextures.characterUp;

		else if(dir == Direction.South)
			activeSprite = StaticTextures.characterDown;

	}
	public StaticInventoryData.GameObject useHotkey(int id) {
		return hotKeys.get(id);
	}
	public void renderActionbar(SpriteBatch sb) {
		//hotkeybg.draw(sb);
		StaticInventoryData.invPics[StaticInventoryData.objId.get(hotKeys.get(1))].setPosition(200, 100);
		StaticInventoryData.invPics[StaticInventoryData.objId.get(hotKeys.get(1))].draw(sb);
		for (int i = 2; i < 6; i++) {
			if (hotKeys.get(i) != StaticInventoryData.GameObject.Nothing) {
				StaticInventoryData.invPics[StaticInventoryData.objId.get(hotKeys.get(i))].setPosition(200+64*(i-1), 100);
				StaticInventoryData.invPics[StaticInventoryData.objId.get(hotKeys.get(i))].draw(sb);
			}
		}
	}

	public void setActiveSprite(int i){	
		if(type != Type.Stay){

			Sprite[] anim = sprites.get(type);
			animlength = anim.length;
			activeSprite = anim[i];

		}
	}
}

